package com.liu.netty.controller;

import com.liu.netty.entity.DriverParams;
import com.liu.netty.netty.ClientManager;
import com.liu.netty.netty.ProtocolContant;
import com.liu.netty.pojo.Message;
import com.liu.netty.service.CollectService;
import com.liu.netty.util.MessageUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/collect")
public class CollectController {

    @Autowired
    private CollectService collectService;

    @GetMapping
   public String hello(){
       return "hello world !!";
   }

    @GetMapping("/clients")
       public Map clients(){
         return ClientManager.getAllClient();
       }


    @GetMapping("/setParams/{address}")
    public Map clients(@PathVariable String address, @RequestBody DriverParams params){

        collectService.sendCommand(2,address,null,null);

        Map map = new HashMap();
        map.put("msg","读取设备参数！！");
        return map;
    }

    /**
     *  读取设备参数
     * @param address
     * @return
     */
    @GetMapping("/params/{address}")
    public Map clients(@PathVariable String address){

        collectService.sendCommand(3,address,null,null);

        Map map = new HashMap();
        map.put("msg","读取设备参数！！");
        return map;
    }



    @GetMapping("/version/{address}")
    public Map clientVersion(@PathVariable String address){

        collectService.sendCommand(4,address,null,null);
        Map map = new HashMap();
        map.put("msg","读取软件版本成功！！");
        return map;
    }
    /**
     * 客户端时间
     * @param address
     * @return
     */
    @GetMapping("/timeUpdate/{address}")
    public Map clientUpdateTime(@PathVariable String address){
        collectService.sendCommand(5,address,null,null);
        Map map = new HashMap();
        map.put("msg","读取时间成功！！");
        return map;
    }

    /**
     * 客户端时间
     * @param address
     * @return
     */
    @GetMapping("/time/{address}")
    public Map clientTime(@PathVariable String address){
        collectService.sendCommand(6,address,null,null);
        Map map = new HashMap();
        map.put("msg","读取时间成功！！");
        return map;
    }

    /**
     * 获取设备的自检报告
     * @param address
     * @return
     */
    @GetMapping("/check/{address}")
    public Map clientCheck(@PathVariable String address){
        collectService.sendCommand(7,address,null,null);

        Map map = new HashMap();
        map.put("msg","获取设备的自检报告！！");
        return map;
    }

    /**
     *  获取设备的传感器信息
     * @param address
     * @return
     */
    @GetMapping("/sensor/{address}")
    public Map clientSensor(@PathVariable String address){
        collectService.sendCommand(8,address,null,null);

        Map map = new HashMap();
        map.put("msg"," 获取设备的传感器信息！！");
        return map;
    }

    /**
     *  拍照处理
     * @param address
     * @return
     */
    @GetMapping("/shot/{address}/{camway}")
    public Map clientShot(@PathVariable String address,@PathVariable String canWay ){
        collectService.sendCommand(9,address,null,canWay);

        Map map = new HashMap();
        map.put("msg","拍照请求成功！！");
        return map;
    }


}
